<admintpl file="header" />
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="javascript:;">店铺列表</a></li>
        <li><a href="{:U('Store/insert')}" target="_self">添加店铺</a></li>
    </ul>
    <form class="well form-search" method="post" action="{:U('Store/index')}">
        关键字：
        <input type="text" name="keyword" style="width: 200px;" value="{$formget.keyword|default=''}" placeholder="请输入用户名称或店铺名称">

        <input type="submit" class="btn btn-primary" value="搜索" />
        <a class="btn btn-danger" href="{:U('Store/index')}">清空</a>
    </form>
    <form class="js-ajax-form" action="" method="post">
        <div class="table-actions">
            <notempty name="term">
                <button class="btn btn-primary btn-small js-ajax-submit" type="submit" data-action="{:U('Store/listorders')}">{:L('SORT')}</button>
            </notempty>
            <button class="btn btn-primary btn-small js-ajax-submit" type="submit" data-action="{:U('Store/check',array('state'=>1))}" data-subcheck="true">开启</button>
            <button class="btn btn-primary btn-small js-ajax-submit" type="submit" data-action="{:U('Store/check',array('state'=>2))}" data-subcheck="true">关闭</button>
            <button class="btn btn-danger btn-small js-ajax-submit" type="submit" data-action="{:U('Store/delete')}" data-subcheck="true" data-msg="您确定删除吗？">{:L('DELETE')}</button>
        </div>
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="15"><label><input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x"></label></th>
                <!--<th width="50">{:L('SORT')}</th>-->
                <th width="50">ID</th>
                <th width="50">编号</th>
                <th>用户名</th>
                <th>推广码</th>
                <th width="50">店铺名</th>
                <th width="50">店铺性质</th>
                <th>所在地</th>
                <th width="100">分享二维码</th>
                <th width="110">小程序码</th>
                <th width="100">添加时间</th>
                <th width="50">状态</th>
                <th width="70">操作</th>
            </tr>
            </thead>
            <volist name="store" id ="sto">
                <tr>
                    <td><input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]" value="{$sto.store_id}" title="ID:{$vo.store_id}"></td>
                    <!--<td><input name="listorders[{$vo.store_id}]" class="input input-order" type="text" size="5" value="{$vo.listorder}"></td>-->
                    <td>{$sto.store_id}</td>
                    <td>{$sto.serial_number}</td>
                    <td>{$sto.user_name}</td>
                    <td>{$sto.promoters_code}</td>
                    <td>{$sto.store_name}</td>
                    <td>{$sto.store_type_value}</td>
                    <td>{$sto.region_name}{$sto.address}</td>
                    <td>
                        <a href="javascript:;" class="btn btn-primary qr_code" data-src="{$sto.qr_code}">查看二维码</a>
                    </td>
                    <td>
                        <if condition="$sto['applet_code']">
                            <a href="javascript:;" class="btn btn-primary applet_code" data-applet_code="{$sto.applet_code}">查看小程序码</a>
                            <else/>
                            <a href="javascript:;" class="btn btn-success getApplet_code" data-id="{$sto.store_id}">获取小程序码</a>
                        </if>
                    </td>
                    <td>{$sto.add_time|date="Y-m-d H:i",###}</td>
                    <td><if condition="$sto.state eq 1">已开启<elseif condition="$sto.state eq 2" />已关闭<else />未选择</if></td>
                    <td attr-id="{$sto.store_id}">
                        <a href="{:U('Store/revise',array('store_id'=>$sto['store_id']))}">{:L('EDIT')}</a>
                    </td>
                </tr>
            </volist>
        </table>
        <div class="pagination">{$page}</div>
    </form>
</div>
<script src="__PUBLIC__/js/common.js"></script>
<script src="__PUBLIC__/layer/layer.js"></script>
<script type="text/javascript">
    $(".qr_code").click(function(){
        var src = $(this).attr('data-src');
        if(src){
            var str = "<img style='width:250px;height: 250px;' src="+src+">";
            layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                area: ['auto'],
                skin: 'layui-layer-nobg', //没有背景色
                shadeClose: true,
                content: str
            });
        }else{
            layer.msg('二维码信息错误');
            return false;
        }

    });
    $(".applet_code").click(function(){

        var src = $(this).attr('data-applet_code');
        if(src){
            var str = "<img style='width:250px;height: 250px;' src="+src+">";
            layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                area: ['auto'],
                skin: 'layui-layer-nobg', //没有背景色
                shadeClose: true,
                content: str
            });
        }else{
            layer.msg('小程序码信息错误');
            return false;
        }
    })

    $(".getApplet_code").click(function(){
        var store_id = $(this).attr('data-id');
        var url = "{:U('Store/getAppletCode')}";
        if(!store_id){
            layer.msg('店铺ID错误');
            return false;
        }
        var index = layer.load(0, {
            shade: false
        }); //0代表加载的风格，支持0-2
        $.post(url,{
            store_id:store_id
        },function(data){
            var res = JSON.parse(data);
            layer.closeAll('loading');
            if(res.code == 1){
                layer.msg(res.msg,function(){
                    window.location.reload();
                })
            }else{
                layer.msg(res.msg);
                return false;
            }
        })

    })

    //查看统计信息
    $(".detail").click(function(){
        var store_id = $(this).attr('data-id');
        var url = "{:U('Store/postData')}";
        $.post(url,{
            store_id:store_id
        },function(data){
            var res = JSON.parse(data);
            if(res.code == 1){
                $.each(res.list,function(index,item){

                })
                layer.open({
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['420px', '240px'], //宽高
                    content: 'html内容'
                });
            }else{
                layer.msg('暂无数据');
                return false;
            }
        })
    })

    $("button.btn-add").click(function () {
        location.href = "{:U('Store/insert')}";
    })
    $("button.btn-edit").click(function () {
        location.href = "{:U('Store/revise')}&store_id="+$(this).attr('attr-id');
    })
</script>
</body>
</html>
